import Vue from 'vue'
import LS from 'store'

export function getSelectMap(opts) {
    console.log(opts);
    return Vue.axios.post('/dict/findLableByParentCoded.do', {
        parent_coded: opts.parentId
    })
}
export function getSelectMapTemp(opts) {
    console.log(opts);
    return Vue.axios.post('/dict/findLableByParentCoded.do', {
        parent_coded: opts.parentId
    })
}
export function getSelectMapTemp2(opts) {
    console.log(opts);
    return Vue.axios.post('/dict/findLableByParentCoded.do', {
        parent_coded: opts.parentId
    })
}

export function getCreateNames() {
    return Vue.axios.post('/needsToSupplier/selectCreateName.do');
}
export function getFileUrl(opts) {
    let apiUrl = '/cvdbSupplier/previewFile.do',
        apiUrl2 = '/cvdbSupplier/download.do'
    return Vue.axios.post(apiUrl, {
        cvdbId: opts.fileUrl,
        isSave: opts.isSave,
        flag: opts.flag
    });
}
export function removeTempFiles(opts) {
    return Vue.axios.post('/cvdbSupplier/removeTemFile.do', {
        name: opts.name
    });
}

// 新字典接口
export function findWorkCityForPlace(opts) {
    return Vue.axios.post('/dict/findWorkCityForPlace.do', opts);
}

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F');
}
// 文件上传
export function doUploading(opts) {
    return Vue.axios.post(`/cvdbSupplier/doUploading.do`, opts);
}
// 文件下载
export function downloadFile(fileUrl) {
    let tk = LS.get('token')
    let tt = URLencode(fileUrl)
    return Vue.axios.get(`/cvdbSupplier/download.do?tt=${tt}&t=${tk}`, { responseType: 'blob' });
}
// 文件删除
export function removeFile(opts) {
    return Vue.axios.post(`/cvdbSupplier/removeFile.do`, opts);
}
  